package oj;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Day47S {
    static class People{
        public int height;
        public int weight;
        public People(int weight,int height){
            this.weight=weight;
            this.height=height;
        }
    }
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int num=sc.nextInt();
            People[] peoples=new People[num];
            for(int i=0;i<num;i++){
                int index=sc.nextInt();
                peoples[index-1]=new People(sc.nextInt(),sc.nextInt());
            }
            Arrays.sort(peoples,new Comparator<People>(){
                @Override
                public int compare(People p1,People p2){
                    return p1.height==p2.height?p1.weight-p2.weight:p1.height-p2.height;
                }
            });
            int[] dp=new int[num];
            Arrays.fill(dp,1);
            int max=Integer.MIN_VALUE;
            for(int i=0;i<num;i++){
                for(int j=i-1;j>=0;j--){
                    if(peoples[i].weight>peoples[j].weight || (peoples[i].weight==peoples[j].weight)&&peoples[i].height
                            ==peoples[j].height){
                        dp[i]=Math.max(dp[i],dp[j]+1);
                    }
                    max=Math.max(dp[i],max);
                }
            }
            System.out.println(max);
        }
    }
}
